#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<unordered_set>
using namespace std;

class Solution{
    public:
    vector<vector<string>> ans1(vector<string>& strs){
        unordered_map<string, vector<string>> map;
        for(string& str: strs){
            string key = str;
            sort(key.begin(), key.end());
            map[key].emplace_back(str);         //push_back
        }
        vector<vector<string>> ret;
        for(auto it = map.begin(); it != map.end(); it++){
            ret.emplace_back(it->second);
        }
        return ret;
    }
};

void test(){
    Solution s;
    vector<string> str1 = {"eat", "tea", "tan", "ate", "nat", "bat"};
    vector<vector<string>> ret = s.ans1(str1);
    for(auto it = ret.begin(); it != ret.end(); it++){
        for(auto st = it->begin(); st != it->end(); st++){
            //迭代器取值使用*
            cout << *st << " " << ends;
        }
        cout << endl;
    }

}

int main(void){
    test();

    return 0;
}